<template>
  <el-dialog v-if="dialogVisible" title="选择">
    <el-select v-model="selectedValue" placeholder="请选择">
      <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>
    <span class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    name: 'ChooseComponent',
    props: {
      visible: Boolean
    },
    data() {
      return {
        dialogVisible: this.visible,
        selectedValue: '',
        options: [
          { label: '选项1', value: 'option1' },
          { label: '选项2', value: 'option2' },
        ]
      };
    },
    watch: {
      visible(newVal) {
        this.dialogVisible = newVal;
      },
      dialogVisible(newVal) {
        this.$emit('update:visible', newVal);
      }
    },
    methods: {
      handleConfirm() {
        this.$emit('confirm', this.selectedValue);
        this.dialogVisible = false;
      }
    }
  }
</script>
